package com.itheima.web;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import com.itheima.entity.Result;
import com.itheima.res.ExcelRes;
import com.itheima.service.ReportService;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.web.bind.annotation.*;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/report")
public class ReportController {

    @Reference
    private ReportService reportService;

    @GetMapping("/findOperationalData")
    public Result findOperationalData() {
        return new Result(reportService.findOperationalData());
    }

//    @PostMapping("/createExcel")
//    public Result createExcel(@RequestBody ExcelRes excelRes) {
//        TemplateExportParams params = new TemplateExportParams("report_template.xlsx");
//        Map data = new HashMap<>();
//
//        Workbook workbook = ExcelExportUtil.exportExcel(params, data);
//        try {
//            OutputStream os = new FileOutputStream("E:/report_template.xlsx");
//            workbook.write(os);
//            os.flush();
//            os.close();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        return new Result(true);
//    }


}
